package com.ydd.controller.admin;

import com.ydd.dto.MenuDTO;
import com.ydd.entity.SysMenu;
import com.ydd.result.Result;
import com.ydd.service.MenuService;
import com.ydd.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys_menu")
@Slf4j
@Api(tags = "菜单管理接口")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 更新菜单
     *
     * @param menuDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("更新菜单")
    public Result update(@RequestBody MenuDTO menuDTO) {
        menuService.update(menuDTO);
        return Result.success();
    }

    /**
     * 根据id删除菜单
     *
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("根据id删除菜单信息")
    public Result del(Integer id) {
        menuService.del(id);
        return Result.success();
    }

    /**
     * 获取所有菜单
     *
     * @return
     */
    @GetMapping("/allData")
    @ApiOperation("获取所有菜单")
    public Result allData() {
        List<MenuVO> menuVOList = menuService.allData();
        return Result.success(menuVOList);
    }

    /**
     * 添加菜单信息
     *
     * @param menuDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加菜单")
    public Result add(@RequestBody MenuDTO menuDTO) {
        menuService.add(menuDTO);
        return Result.success();
    }

    /**
     * 根据id查看详细信息
     *
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("根据id查看详细信息")
    public Result<SysMenu> rowInfo(Integer id) {
        SysMenu sysMenu = menuService.rowInfo(id);
        return Result.success(sysMenu);
    }
}
